package tech.dx.springdb.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.dx.springdb.entity.Teacher;
import tech.dx.springdb.respository.TeacherRepository;
import tech.dx.springdb.service.TeacherService;

import java.util.Optional;

/**
 * @ClassName TeacherServiceImpl
 * @Description TODO
 * @Author daoxuan
 * @Date 2019/4/1 10:40
 * @Version 1.0
 */
@Service
@Transactional
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherRepository teacherRepository;
    @Override
    public Teacher add(Teacher teacher) {
        return  teacherRepository.save(teacher);
    }

    @Override
    public Teacher update(Teacher teacher) {
        Teacher save = teacherRepository.save(teacher);
        return save;
    }

    @Override
    public Teacher getById(long id) {
        Optional<Teacher> byId = teacherRepository.findById(id);
        return byId.isPresent()?byId.get():null;
    }
}
